<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<!DOCTYPE html>
<html lang="en">
	<head>
		<meta charset="utf-8">
		<title>Login</title>
		<meta name="description" content="">
		<meta name="author" content="Vincent Garreau" />
		<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
		<link rel="stylesheet" media="screen" href="../css/loginstyle.css">
		<link rel="stylesheet" type="text/css" href="../css/loginreset.css" />
	</head>
	<body>
	<div id="particles-js">
		<div class="login" id="divlogin">
			<div class="login-top">登录</div>
			<div class="login-center clearfix">
				<div class="login-center-img"><img src="../img/name.png" /></div>
				<div class="login-center-input">
					<input id="inpusername" type="text" name="" placeholder="请输入您的用户名" onfocus="this.placeholder=''" onblur="this.placeholder='请输入您的用户名'" />
					<div class="login-center-input-text divusernametxt">用户名</div>
				</div>
			</div>
			<div class="login-center clearfix">
				<div class="login-center-img"><img src="../img/password.png" /></div>
				<div class="login-center-input">
					<input id="inppassword" type="password" name="" placeholder="请输入您的密码" onfocus="this.placeholder=''" onblur="this.placeholder='请输入您的密码'" />
					<div class="login-center-input-text divpasswordtxt">密码</div>
				</div>
			</div>
			<div class="login-button">登录</div>
		</div>
		<div class="sk-rotating-plane"></div>
	</div>
	<script type="text/javascript" src="../js/jquery-3.3.1.js" ></script>
	<script src="../lib/layer/layer.js"></script>
	<!-- 以下2019-1-7徐震霖添加 -->
	<script src="../lib/md5.js"></script>
	<script src="../lib/Constant.js"></script>
	<script type="text/javascript">
		function hasClass(elem, cls) {
			cls = cls || '';
			if(cls.replace(/\s/g, '').length == 0) return false; //当cls没有参数时，返回false
			return new RegExp(' ' + cls + ' ').test(' ' + elem.className + ' ');
		}
		function addClass(ele, cls) {
			if(!hasClass(ele, cls)) {
				ele.className = ele.className == '' ? cls : ele.className + ' ' + cls;
			}
		}
		function removeClass(ele, cls) {
			if(hasClass(ele, cls)) {
				var newClass = ' ' + ele.className.replace(/[\t\r\n]/g, '') + ' ';
				while(newClass.indexOf(' ' + cls + ' ') >= 0) {
					newClass = newClass.replace(' ' + cls + ' ', ' ');
				}
				ele.className = newClass.replace(/^\s+|\s+$/g, '');
			}
		}
		/* 回车键触发登录 */
		$("body").keydown(function(e) {
			if (e.which == 13) {
				$(".login-button").trigger("click");
			}
		});
		/* 点击登录 */
		document.querySelector(".login-button").onclick = function() {
			var username=$("#inpusername").val().trim();
			var password=$("#inppassword").val().trim();
			if(username==null || username=="" || username==undefined){
				$("#inpusername").focus();
				return;
			}
			if(password==null || password=="" || password==undefined){
				$("#inppassword").focus();
				return;
			}
			
			/**
			 * 2019-1-7徐震霖修改添加
			 */
			if(password.length<6 || password.length>18){
				layer.alert('密码长度不符合规范!', {icon: 2});
				return;
			}
			
			/**
			 * 2019-1-7徐震霖修改添加
			 */
			var enpwd = hex_md5(fix(Encryption_key,password));
			$("#inppassword").val(enpwd);
			
			var index = layer.load(0, {shade: 0.1});
			$.ajax({
				type : 'get',
				url : '../sysadminusermanager/adminuserlogin?userid='+username+'&pwd='+enpwd,//2019-1-7徐震霖修改添加
				datatype : 'json',
				success : function(data) {
					if (data.code == 10001) {
						window.location.href = "../html/index.jsp";
					} else {
						layer.alert(data.msg, {icon: 2});
						layer.close(index);
						$("input").val("");
					}
				},
				error:function(){
    	        	layer.alert(data.msg, {icon: 2});
    	        }
			});
		}
	</script>
	</body>
</html>